/*
 *  用不着这么复杂
 */
var trim = function(str){
    return str.replace(/^\s+|\s+$/);
}
var getClass = function(ele){
    var className = ele.className;
    return className && typeof className.split == "function" ? className.split(/\s+/) : [];
}
var setClass = function(ele, cla){
    ele.className = cla;
}
var hasClass = function(ele, cla){
    var classNames = getClass(ele), i = 0, len = classNames.length;
    for (; i < len; i++) {
        var cn = classNames[i] && trim(classNames[i]);
        if (cn == trim(cla)) {
            return true;
        }
    }
    return false;
    
}
var addClass = function(ele, cla){
    if (!hasClass(ele)) {
        var classNames = getClass(ele);
        classNames.push(cla);
        setClass(ele, classNames.join(" "));
    }
}
var removeClass = function(ele, cla){
    var classNames = getClass(ele), i = 0, len = classNames.length;
    for (; i < len; i++) {
        if (hasClass(cla)) {
            classNames.splice(i - 1, 1);
        }
    }
    setClass(ele, classNames.join(" "))
    
}
